package org.meow.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.meow.dto.ArticleDTO;
import org.meow.entity.Article;
import org.meow.result.Result;
import org.meow.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * &#064;Date: 24/04/26-22:24
 * &#064;Description:
 */
@RestController
@RequestMapping("/article")
@Tag(name = "文章管理")
public class ArticleController {

  @Autowired
  private ArticleService articleService;

  @PostMapping
  @Operation(summary = "添加文章")
  public Result<String> addArticle(@RequestBody ArticleDTO articleDTO) {
    articleService.save(articleDTO);
    return Result.success();
  }

  @DeleteMapping("/{id}")
  @Operation(summary = "删除文章")
  public Result<String> deleteArticle(@PathVariable Integer id) {
    return articleService.delete(id) ? Result.success(): Result.error("删除失败");
  }

  @PutMapping
  @Operation(summary = "更新文章")
  public Result<String> updateArticle(@RequestBody Article article) {
    return articleService.update(article) ? Result.success(): Result.error("更新失败");
  }

}
